package com.java.test.system.gametfeemanage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.java.test.dto.PageResultDTO;
import com.java.test.dto.ResponseDTO;
import com.java.test.system.gametfeemanage.constant.GameFeeResponseCodeConst;
import com.java.test.system.gametfeemanage.dto.GameFeeAddDTO;
import com.java.test.system.gametfeemanage.dto.GameFeeQueryDTO;
import com.java.test.system.gametfeemanage.dto.GameFeeUpdateDTO;
import com.java.test.system.gametfeemanage.entity.GameFeeEntity;
import com.java.test.system.gametfeemanage.vo.GameFeeVO;
import com.java.test.system.gametypemanage.GameTypeManageDAO;
import com.java.test.system.gametypemanage.constant.GameTypeResponseCodeConst;
import com.java.test.system.gametypemanage.entity.GameTypeEntity;
import com.java.test.util.SmartBeanUtil;
import com.java.test.util.SmartPageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 游戏抽水server
 * @author lijie1
 */
@Service
public class GameFeeManageService {

    @Autowired
    private GameFeeManageDAO gameFeeManageDAO;

    /**
     * 获取游戏抽水列表
     * @author lijie1
     * @date 2020/6/29 0029 12:39
     */
    public ResponseDTO<PageResultDTO<GameFeeVO>> getGameFeeList(GameFeeQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        List<GameFeeEntity> entityList = gameFeeManageDAO.selectGameFeeList(queryDTO);
        PageResultDTO<GameFeeVO> pageResultDTO = SmartPageUtil.convert2PageResult(page, entityList, GameFeeVO.class);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 游戏抽水添加
     * @author lijie1
     * @date 2020/6/29 0029
     */
    public ResponseDTO<String> addGameFee(GameFeeAddDTO addDTO) {
        GameFeeEntity entity = gameFeeManageDAO.getByGName(addDTO.getName());
        if (entity != null) {
            return ResponseDTO.wrap(GameFeeResponseCodeConst.ALREADY_EXIST);
        }
        gameFeeManageDAO.insertGameFee(addDTO);
        return ResponseDTO.succ();
    }

    /**
     * 游戏抽水查询BYId
     * @author lijie1
     * @date 2020/6/29 0029
     */
    public ResponseDTO<GameFeeVO> selectById(String id) {
        GameFeeEntity entity = gameFeeManageDAO.getById(id);
        if (entity == null) {
            return ResponseDTO.wrap(GameFeeResponseCodeConst.NOT_EXIST);
        }
        GameFeeVO configDTO = SmartBeanUtil.copy(entity, GameFeeVO.class);
        return ResponseDTO.succData(configDTO);
    }

    /**
     * 修改游戏抽水
     * @author lijie1
     * @date 2020/6/29 0029
     */
    public ResponseDTO<String> updateGameFee(GameFeeUpdateDTO updateDTO) {
        GameFeeEntity entity = gameFeeManageDAO.getById(updateDTO.getId());
        //游戏类型不存在
        if (entity == null) {
            return ResponseDTO.wrap(GameFeeResponseCodeConst.NOT_EXIST);
        }
        GameFeeEntity alreadyEntity = gameFeeManageDAO.getByKeyExcludeId(updateDTO.getName(),updateDTO.getGameType(), updateDTO.getId());
        if (alreadyEntity != null) {
            return ResponseDTO.wrap(GameFeeResponseCodeConst.ALREADY_EXIST);
        }
        gameFeeManageDAO.updateById(updateDTO);
        return ResponseDTO.succ();
    }

    /**
     * 删除游戏抽水
     * @author lijie1
     * @date 2020/6/29 0029
     */
    public ResponseDTO<String> deleteById(String id) {
        GameFeeEntity entity = gameFeeManageDAO.getById(id);
        //游戏类型不存在
        if (entity == null) {
            return ResponseDTO.wrap(GameFeeResponseCodeConst.NOT_EXIST);
        }
        gameFeeManageDAO.deleteById(id);
        return ResponseDTO.succ();
    }
}
